package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.FormDataResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.ProcessInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.SubmitFormRequest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.FormsApi")
public class FormsApi {
    private ApiClient apiClient;

    public FormsApi() {
        this(new ApiClient());
    }

    @Autowired
    public FormsApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get form data
     *
     * <p><b>200</b> - Indicates that form data could be queried.
     * <p><b>404</b> - Indicates that form data could not be found.
     * @param taskId The taskId parameter
     * @param processDefinitionId The processDefinitionId parameter
     * @return FormDataResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public FormDataResponse getFormData(String taskId, String processDefinitionId) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/form/form-data").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "taskId", taskId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processDefinitionId", processDefinitionId));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<FormDataResponse> returnType = new ParameterizedTypeReference<FormDataResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Submit task form data
     *
     * <p><b>200</b> - Indicates request was successful and the form data was submitted
     * <p><b>204</b> - If TaskId has been provided, Indicates request was successful and the form data was submitted. Returns empty
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return ProcessInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ProcessInstanceResponse submitForm(SubmitFormRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/form/form-data").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<ProcessInstanceResponse> returnType = new ParameterizedTypeReference<ProcessInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
